﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using QuanLyBanHang.DataConnection;
using System.Windows.Forms;

namespace QuanLyBanHang.QuerySQL
{
    class ClassNSX
    {
        Connect conn = new Connect();
        public DataTable ShowNSX()
        {
            DataTable tb = new DataTable(); ;
            try
            {
                string sql = "select *from NHASX";
                tb = conn.getTable(sql);
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
            return tb;
        }
        //
        public void ThemNSX(string mansx, string tennsx, string sdt, string diachi)
        {
            try
            {
                string sql = "insert into NHASX values('" + mansx + "',N'" + tennsx + "','"+sdt+"',N'"+diachi+"')";
                conn.ExcuteQuerySql(sql);
                MessageBox.Show("Thêm thành công !!!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
        }
        //
        public void SuaNSX(string mansx, string tennsx, string sdt, string diachi)
        {
            try
            {
                string sql = "update NHASX set TENNSX = N'" + tennsx + "', SODTNSX = '"+ sdt+"', DIACHINSX =N'"+diachi+"' where MANSX = '" + mansx + "' ";
                conn.ExcuteQuerySql(sql);
                MessageBox.Show("Sửa thành công !!!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
        }
        //
        public void XoaNSX(string mansx)
        {
            try
            {
                string sql = "delete NHASX where MANSX = '" + mansx + "'";
                conn.ExcuteQuerySql(sql);
                MessageBox.Show("Xóa thành công !!!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
        }
        //
        public DataTable tk_mansx(string ma)
        {
            DataTable tb = new DataTable(); ;
            try
            {
                string sql = "select *from NHASX where MANSX like '%" + ma + "%'";
                tb = conn.getTable(sql);
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
            return tb;
        }
        //
        public DataTable tk_tennsx(string ten)
        {
            DataTable tb = new DataTable(); ;
            try
            {
                string sql = "select *from NHASX where TENNSX like N'%" + ten + "%'";
                tb = conn.getTable(sql);
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
            return tb;
        }
    }
}
